package com.chengyu.core.controller;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chengyu.core.component.OperationLog;
import com.chengyu.core.domain.form.GoodsPublishForm;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.CommonException;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.*;
import com.chengyu.core.request.PageParamRequest;
import com.chengyu.core.service.AssistService;
import com.chengyu.core.service.content.ArticleService;
import com.chengyu.core.utils.StringUtils;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 援助 前端控制器
 * </p>
 *
 * @author wenlj
 * @since 2023-10-29
 */
@Api(tags = "援助领养", description = "MemberAddressController")
@Controller
@RequestMapping("/assist")
public class AssistController extends UserBaseController {
    @Autowired

    private AssistService assistService;

    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "int"),
            @ApiImplicitParam(name = "title", value = "标题", dataType = "string"),
//            @ApiImplicitParam(name = "author", value = "作者", dataType = "string")
    })
    public CommonResult<CommonPage<Assist>> getList(@Validated Assist request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(assistService.getList(request, pageParamRequest)));
    }


    @ApiOperation(value = "个人分页列表")
    @RequestMapping(value = "/memberlist", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "int"),
            @ApiImplicitParam(name = "title", value = "标题", dataType = "string"),
//            @ApiImplicitParam(name = "author", value = "作者", dataType = "string")
    })
    public CommonResult<CommonPage<Assist>> getMemberList(@Validated Assist request, @Validated PageParamRequest pageParamRequest) throws ServiceException {

//        UmsMember member = getCurrentMember();
        request.setMemberId(getCurrentMemberId());
        return CommonResult.success(CommonPage.restPage(assistService.getList(request, pageParamRequest)));
    }

    @ApiOperation(value = "详情")
    @ResponseBody
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<Assist> detail(@PathVariable(value = "id") Integer id) {
        return CommonResult.success(assistService.getVoByFront(id));
    }



    @ApiOperation(value = "添加编辑")
    @OperationLog
    @ResponseBody
    @RequestMapping(value = {"/add"}, method = RequestMethod.POST)
    public CommonResult<String> editSubmit(Assist assist) throws CommonException, ServiceException {

        UmsMember member = getCurrentMember();
        assist.setMemberId(getCurrentMemberId());

        assistService.pushAssist(assist);
//		goodsService.publishGoodsNew(getCurrentShop(), publishForm);
        return CommonResult.success(null);
    }


    @ApiOperation(value = "删除")
    @OperationLog
    @ResponseBody
    @RequestMapping(value = {"/del"}, method = RequestMethod.DELETE)
    public CommonResult<String> del(Integer id) throws CommonException, ServiceException {


        assistService.deleteByIdWithMemberId(id,getCurrentMemberId());
//		goodsService.publishGoodsNew(getCurrentShop(), publishForm);
        return CommonResult.success(null);
    }
}

